package main

import (
	"sync"
)

var maps = map[int]int{
	1: 100,
	2: 200,
	3: 300,
}

func withoutLock() {
	wg := sync.WaitGroup{}

	for i:=0; i<10000; i++ {
		wg.Add(1)
		go func(){
			_ = maps[3]
			_ = maps[2]
			_ = maps[1]
			wg.Done()
		}()
	}
	wg.Wait()
}


func withLock() {
	wg := sync.WaitGroup{}
	mu := sync.RWMutex{}

	for i:=0; i<10000; i++ {
		wg.Add(1)
		go func() {
			mu.RLock()
			_ = maps[3]
			_ = maps[2]
			_ = maps[1]
			mu.RUnlock()
			wg.Done()
		}()
	}
	wg.Wait()
}

func main() {
	withoutLock()
}
